$(document).ready(function() {
    $("#selectall").click(function() {
        if ($("#selectall").prop("checked") == true) {
            $(".chek_all").prop("checked", true);
        } else {
            $(".chek_all").prop("checked", false);
        }
    });


    var switches = document.querySelectorAll('input[type="checkbox"].ios-switch');
    for (var i = 0, sw; sw = switches[i++]; ) {
        var div = document.createElement('div');
        div.className = 'switch-div';
        sw.parentNode.insertBefore(div, sw.nextSibling);
    }


    $(".manage_alert_chkbox").click(function() {
        var checked_alert = $(this).is(":checked");
        var alert_id = $(this).attr('alert_id');
        var postdata = {};
        postdata['checked_alert'] = checked_alert;
        postdata['alert_id'] = alert_id;
        postdata['status'] = 'managestatus';
        jQuery.post(BASE_PATH + '/member/alertupdate', postdata, function(result) {

        });
    });

    $(".ma_receive_update").change(function() {
        var ma_receive_update = $(this).val();
        var alert_id = $(this).attr('alert_id');
        var postdata = {};
        postdata['ma_receive_update'] = ma_receive_update;
        postdata['alert_id'] = alert_id;
        postdata['status'] = 'ma_receive_update';
        jQuery.post(BASE_PATH + '/member/alertupdate', postdata, function(result) {

        });
    });

    $(".ma_next_time").change(function() {
        var ma_next_time = $(this).val();
        var alert_id = $(this).attr('alert_id');
        var postdata = {};
        postdata['ma_next_time'] = ma_next_time;
        postdata['alert_id'] = alert_id;
        postdata['status'] = 'ma_next_time';
        jQuery.post(BASE_PATH + '/member/alertupdate', postdata, function(result) {

        });
    });





    $(".wysihtml5-editor").each(function() {
        $(this).wysihtml5({
            "font-styles": true, //Font styling, e.g. h1, h2, etc. Default true
            "emphasis": true, //Italics, bold, etc. Default true
            "lists": true, //(Un)ordered lists, e.g. Bullets, Numbers. Default true
            "html": false, //Button which allows you to edit the generated HTML. Default false
            "link": false, //Button to insert a link. Default true
            "image": false, //Button to insert an image. Default true,
            "color": false//Button to change color of font  
        });
    });

	//if($("#CountAvailable").val() == 1){
        if(CountAvailable == 1){
		Morris.Donut({
			element: 'donut-example',
			data: [
				{label: "Saved Properties", value: SavedPropertyData},
				{label: "Property Viewings", value: viewPropertyData},
				{label: "Alerts & Searchs", value: alertPropertyData},
				{label: "Assigned Property", value: AssignpropertyData}

			]
		});
	}
    

    $(".chk_all").click(function() {
        //alert($(this).is(":checked"));
        if ($(this).is(":checked") === true) {
            $('.chk_cls').prop('checked', true);
        } else {
            $('.chk_cls').prop('checked', false);
        }
    });
/*
    $("#send_email").click(function() {
        alert('in');    
        var chkArray = [];
        $(".chek_all:checked").each(function() {
            chkArray.push($(this).val());
        });
        var selected;
        selected = chkArray.join(',');
        $("#ac_property_id").val(selected);
        
        $("#success_frnd_email").show();
        $("#frnd_name").val('');
        $("#frnd_email").val('');
        $("#your_name").val('');
        $("#your_email").val('');
        $("#frnd_tel_no").val('');
        $("#textarea_note").val('');
        
        $("#myModal_client").modal('show');

    });

*/

    $("#delete_all_assign").click(function(){
        var chkArray = [];
        $(".chek_all:checked").each(function() {
            chkArray.push($(this).val());
        });
        var selected_property;
        selected_property = chkArray.join(',');
        var member_id = $("#current_member_id").val();
        
        var postdata = {};
        var obj = $(this);
        postdata['selected_property'] = selected_property;
        postdata['member_id'] = member_id;
        //$("#ac_property_id").val(selected);
        if (chkArray.length != 0) {
           jQuery.post(BASE_PATH + '/member/deleteassign', postdata, function(result) {
           if(result == 1){
            $("#err_delete").show();
            $("#err_delete").html('Property deleted successfully');
                window.setTimeout(function() {
                location.href = SITE_URL + "member/view/member_id/"+member_id;
                }, 3000);
           }
        });
        } else {
            $("#send_email_error").show();
        }
        
    
    });

    $(".email_frnd").click(function() {
        var imag_src = $(this).attr('image_src');
        var status = $(this).attr('status');
        var property_price = $(this).attr('property_price');
        var property_name = $(this).attr('property_name');
        var property_id = $(this).attr('property_id');
        var ref_name = $(this).attr('ref_no') + property_id;
        var property_type = $(this).attr('property_type');
        $("#unique_all").val(property_type);
        if (property_type) {
            $("#col-lg-12").hide();

            var chkArray = [];
            $(".chek_all:checked").each(function() {
                chkArray.push($(this).val());
            });
            var selected;
            selected = chkArray.join(',');
            $("#property_all_id").val(selected);

        }


        $("#show_price").html(property_price);
        $("#status").html(status);
        $("#property_name").html(property_name);
        $("#prp_image").attr('src', imag_src);

        $("#ref_name").html(ref_name);
        $("#send_frnd_email").attr('property_id', property_id);
        if (property_type != 'all') {
            $("#myModal_client").modal('show');
            
        } else {
            if (chkArray.length != 0) {
                $("#myModal_client").modal('show');
				$("#send_email_error").hide();
            } else {
                $("#send_email_error").show();
            }

        }

    });

    $("#send_frnd_email").click(function() {
        //alert('in');
        var frnd_name = $("#frnd_name").val();
        var frnd_email = $("#frnd_email").val();
        var your_name = $("#your_name").val();
        var your_email = $("#your_email").val();
        var frnd_tel_no = $("#frnd_tel_no").val();
        var textarea_note = $("#textarea_note").val();
        var regex = /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/;
        var property_id = $(this).attr('property_id');
		var member_id = $("#current_member_id").val();
        var unique_all = $("#unique_all").val();
        var property_all_id = $("#property_all_id").val();


        $("#error_frnd_name").hide();
        $("#error_frnd_email").hide();
        $("#error_valid_email").hide();
        $("#error_your_name").hide();
        $("#error_your_email").hide();
        $("#frnd_name").removeAttr('style');
        $("#frnd_email").removeAttr('style');
        $("#your_name").removeAttr('style');
        $("#your_email").removeAttr('style');


        if (frnd_name == '') {
            $("#error_frnd_name").show();
            $("#frnd_name").css('border-color', 'red');
            return false;
        } else if (frnd_email == '') {
            $("#error_frnd_email").show();
            $("#frnd_email").css('border-color', 'red');
            return false;
        } else if (frnd_email != '' && regex.test(frnd_email) == false) {
            $("#error_valid_email").show();
            $("#frnd_email").css('border-color', 'red');
            return false;
        } else if (your_name == '') {
            $("#error_your_name").show();
            $("#your_name").css('border-color', 'red');
            return false;
        } else if (your_email == '') {
            $("#error_your_email").show();
            $("#your_email").css('border-color', 'red');
            return false;
        } else if (your_email != '' && regex.test(your_email) == false) {
            $("#error_valid_email").show();
            $("#your_email").css('border-color', 'red');
            return false;
        }

        var postdata = {};
        var obj = $(this);
        postdata['frnd_name'] = frnd_name;
        postdata['frnd_email'] = frnd_email;
        postdata['your_name'] = your_name;
        postdata['your_email'] = your_email;
        postdata['frnd_tel_no'] = frnd_tel_no;
        postdata['textarea_note'] = textarea_note;
        postdata['property_id'] = property_id;
        postdata['unique_all'] = unique_all;
        postdata['property_all_id'] = property_all_id;
        //alert(postdata);
        jQuery.post(BASE_PATH + '/member/sendfriendmail', postdata, function(result) {
            $("#success_frnd_email").show();
            $("#success_frnd_email").html(result);
            window.setTimeout(function() {
                location.href = SITE_URL + "member/view/member_id/"+member_id;
                }, 3000);
            /*window.setTimeout(function() {
             location.href = SITE_URL + "member";
             }, 3000);*/
        });

    });
	
	
	// support ticket
	
	/*$("#member_id").select2({
		placeholder: "Select Client"
	});*/

	
	/** Text Editor **/
	//$('#message').wysihtml5();	
	$('#nt_date1').datepicker({
				format: "dd/mm/yyyy",
			   // startDate: '+1d',
				autoclose: true,
			  //  todayHighlight: true
		 });
	 
	 $('.clockpicker ').clockpicker({
        autoclose: true
    });
	
	
	$('.edit_notification').click( function() {
	//$('#new-ticket-wrapper').slideToggle("fast","linear")
		//alert('here');
		$("#member_id").select2();
		var nt_id = $(this).attr('nt_id');
		
        var nt_date = $(this).attr('nt_date');
		var nt_time = $(this).attr('nt_time');
        var nt_note = $(this).attr('nt_note');
        var member_id = $(this).attr('member_id');
        
		$("#nt_id").val(nt_id);
		//alert(st_time);
        $("#nt_date1").val(nt_date);
		$("#nt_time").val(nt_time);
        $("#nt_note").val(nt_note);
		$("#member_id").select2("val", member_id);
		if (member_id == '') {
            $("#error_add_notification").show();
            $("#error_add_notification").html('Please select client');
            $("#member_id").css('border-color', 'red');
            return false;
        }
        $("#add_btn_notification").html('Update');
        $("#myModalLabel").html('Edit Notification');
		$("#myModal_supportticket").modal('show');
	});
	
	$("#add_btn_notification").click(function() {
	
		var nt_id = $("#nt_id").val();
		
        var member_id = $("#member_id").val();
		
		var nt_date1 = $("#nt_date1").val();
		var nt_time = $("#nt_time").val();
		var nt_note = $("#nt_note").val();
			
        $("#error_add_notification").hide();
         if (member_id == '') {
            $("#error_add_notification").show();
            $("#error_add_notification").html('Please select client');
            $("#member_id").css('border-color', 'red');
            return false;
        } else {
            var postdata = {};
            var obj = $(this);
			
            postdata['nt_id'] = nt_id;
			postdata['member_id'] = member_id;
			postdata['nt_date1'] = nt_date1;
			postdata['nt_time'] = nt_time;
			postdata['nt_note'] = nt_note;
		
            jQuery.post(BASE_PATH + '/notification/list', postdata, function(result) {
                if (result == 1) {
                    $("#success_add_notification").show();
                    window.setTimeout(function() {
                         $("#member_id").select2("val","");
                         $("#success_add_notification").hide();
                         $("#myModal_supportticket").modal('hide');
                         window.location = BASE_PATH + "member/view/member_id/"+member_id;
                    }, 3000);
                }
            });
        }


    });

	
	
});

         